<?php
class CategorysuggestionsController extends AppController {

	var $name = 'Categorysuggestions';

	function index() {
		$this->Categorysuggestion->recursive = 0;
		$this->set('categorysuggestions', $this->paginate());
	}

	function view($id = null) {
		if (!$id) {
			$this->Session->setFlash(__('Invalid categorysuggestion', true));
			$this->redirect(array('action' => 'index'));
		}
		$this->set('categorysuggestion', $this->Categorysuggestion->read(null, $id));
	}

	function add() {
		if (!empty($this->data)) {
			$this->data['Categorysuggestion']['date']=null;
			$this->Categorysuggestion->create();
			if ($this->Categorysuggestion->save($this->data)) {
				if ($this->RequestHandler->isAjax()){
					echo "Thank you!"; 
					$this->autoRender = false;
					  Configure::write("debug", 0); 
					exit();
				} else {
					$this->Session->setFlash(__('The categorysuggestion has been saved', true));
					$this->redirect(array('action' => 'index'));
				}
			} else {
				if ($this->RequestHandler->isAjax()){
					echo ":(";
					exit();
				} else {
				$this->Session->setFlash(__('The categorysuggestion could not be saved. Please, try again.', true));
				}
			}
		}
	}

	function edit($id = null) {
		if (!$id && empty($this->data)) {
			$this->Session->setFlash(__('Invalid categorysuggestion', true));
			$this->redirect(array('action' => 'index'));
		}
		if (!empty($this->data)) {
			if ($this->Categorysuggestion->save($this->data)) {
				$this->Session->setFlash(__('The categorysuggestion has been saved', true));
				$this->redirect(array('action' => 'index'));
			} else {
				$this->Session->setFlash(__('The categorysuggestion could not be saved. Please, try again.', true));
			}
		}
		if (empty($this->data)) {
			$this->data = $this->Categorysuggestion->read(null, $id);
		}
	}

	function delete($id = null) {
		if (!$id) {
			$this->Session->setFlash(__('Invalid id for categorysuggestion', true));
			$this->redirect(array('action'=>'index'));
		}
		if ($this->Categorysuggestion->delete($id)) {
			$this->Session->setFlash(__('Categorysuggestion deleted', true));
			$this->redirect(array('action'=>'index'));
		}
		$this->Session->setFlash(__('Categorysuggestion was not deleted', true));
		$this->redirect(array('action' => 'index'));
	}
}
